package com.deng.eventflow.core.functions;

import com.deng.eventflow.core.PubliclyStateful;
import com.deng.eventflow.core.UniformProcessor;

import java.util.Set;

public class TurnInto extends UniformProcessor implements PubliclyStateful {
    /**
     * The event to turn everything into
     */
    protected final Object m_event;

    /**
     * Instantiates a new function processor
     *
     * @param o
     *          The computable object responsible for the computation
     */
    public TurnInto(Object o)
    {
        super(1, 1);
        m_event = o;
    }

    @Override
    protected boolean compute(Object[] inputs, Object[] outputs)
    {
        outputs[0] = m_event;
        return true;
    }

    @Override
    public synchronized TurnInto duplicate(boolean with_state)
    {
        TurnInto out = new TurnInto(m_event);
        duplicateInto(out);
        return out;
    }

    @Override
    public final void getInputTypesFor(/*@ non_null @*/ Set<Class<?>> classes, int index)
    {
        classes.add(Object.class);
    }

    @Override
    public final synchronized Class<?> getOutputType(int index)
    {
        return m_event.getClass();
    }

    @Override
    public String toString()
    {
        return "Turn into " + m_event;
    }

    /**
     * @since 0.10.2
     */
    @Override
    public Object printState()
    {
        return m_event;
    }

    /**
     * @since 0.10.2
     */
    @Override
    public TurnInto readState(Object o)
    {
        return new TurnInto(o);
    }

    @Override
    public Object getState()
    {
        return 0;
    }
}
